//
// Created by 刘进伟 on 2018/5/22.
//

#include <iostream>
#include "SynAnalyzer.h"

SynAnalyzer::SynAnalyzer(TokeErgo &tokens) : tokeErgo(tokens)
{
    InitLL1Table();
    CreateTable();
    synStack.push(LexType::Program);
    synDeepth.push(0);
}

SynAnalyzer::~SynAnalyzer()
{

}

void SynAnalyzer::genSyntax() {
    while (!synStack.empty()){
        if(tokeErgo.isEmpty()){
            printf("Syntax analysis error(line: %d):Input stack is empty!\n",lineNumber);
            exit(0);
        }else{
            if(synStack.top()>LexType::ENDOFILE){//栈顶是非终极符
                Token & temp=tokeErgo.getCurrentToken();
                lineNumber=temp.lineNumber;
                int objP=LL1TABLE[synStack.top()-LexType::Program][temp.lexType];
                if(objP==-1){//预测错误
                    printf("Syntax analysis error(line: %d):Predict error!( %s )\n",lineNumber,temp.content);
                    exit(0);
                }else{//预测成功
                    //printf("弹出类型为：%d\n,规则号：%d\n",synStack.top(),objP);
                    currentDeepth=synDeepth.top();
                    tokeErgo.printTree(synStack.top(),synDeepth.top());
                    synStack.pop();
                    synDeepth.pop();
                    std::list<LexType >::iterator synIt=synRules[objP].begin();
                    while (synIt!=synRules[objP].end()){
                        synStack.push(*synIt);
                        synDeepth.push(currentDeepth+1);
                        //printf("压入栈数据为：%d\n",synStack.top());
                        synIt++;
                    }
                }
            }else{//栈顶是终极符
                if(synStack.top()==tokeErgo.getCurrentToken().lexType){//终极符匹配成功
                    //printf("VT match success!( %s )\n",tokeErgo.getCurrentToken().content);
                    tokeErgo.printTree(synStack.top(),synDeepth.top());
                    synDeepth.pop();
                    synStack.pop();
                    tokeErgo.goAhead();
                }else{
                    printf("Syntax analysis error(line: %d):VT match error!( %s )\n",
                           lineNumber,tokeErgo.getCurrentToken().content);
                    exit(0);
                }
            }
        }
    }

    if(tokeErgo.isEmpty()){
        printf("Systax analysis success!\n");
    }else{
        if(tokeErgo.getCurrentToken().lexType==LexType::DOT){
            printf("Systax analysis success!\n");
        }else {
            printf("Syntax analysis error!: not match all input lex!\n");
        }
    }
}
void SynAnalyzer::CreateTable()
{
    for(int i=0;i<VN;i++){
        for(int j=0;j<VT;j++){
            LL1TABLE[i][j]=-1;
        }
    }
    LL1TABLE[Program - Program][PROGRAM] = 0;

    LL1TABLE[ProgramHead - Program][PROGRAM] = 1;

    LL1TABLE[ProgramName - Program][ID] = 2;

    LL1TABLE[DeclarePart - Program][TYPE] = 3;
    LL1TABLE[DeclarePart - Program][VAR] = 3;
    LL1TABLE[DeclarePart - Program][PROCEDURE] = 3;
    LL1TABLE[DeclarePart - Program][BEGIN] = 3;

    LL1TABLE[TypeDecpart - Program][VAR] = 4;
    LL1TABLE[TypeDecpart - Program][PROCEDURE] = 4;
    LL1TABLE[TypeDecpart - Program][BEGIN] = 4;

    LL1TABLE[TypeDecpart - Program][TYPE] = 5;

    LL1TABLE[TypeDec - Program][TYPE] = 6;

    LL1TABLE[TypeDecList - Program][ID] = 7;

    LL1TABLE[TypeDecMore - Program][VAR] = 8;
    LL1TABLE[TypeDecMore - Program][PROCEDURE] = 8;
    LL1TABLE[TypeDecMore - Program][BEGIN] = 8;

    LL1TABLE[TypeDecMore - Program][ID] = 9;

    LL1TABLE[TypeId - Program][ID] = 10;

    LL1TABLE[TypeDef - Program][INTEGER] = 11;
    LL1TABLE[TypeDef - Program][CHAR] = 11;

    LL1TABLE[TypeDef - Program][ARRAY] = 12;
    LL1TABLE[TypeDef - Program][RECORD] = 12;

    LL1TABLE[TypeDef - Program][ID] = 13;

    LL1TABLE[BaseType - Program][INTEGER] = 14;

    LL1TABLE[BaseType - Program][CHAR] = 15;

    LL1TABLE[StructureType - Program][ARRAY] = 16;

    LL1TABLE[StructureType - Program][RECORD] = 17;

    LL1TABLE[ArrayType - Program][ARRAY] = 18;

    LL1TABLE[Low - Program][INTC] = 19;

    LL1TABLE[Top - Program][INTC] = 20;

    LL1TABLE[RecType - Program][RECORD] = 21;

    LL1TABLE[FieldDecList - Program][INTEGER] = 22;
    LL1TABLE[FieldDecList - Program][CHAR] = 22;

    LL1TABLE[FieldDecList - Program][ARRAY] = 23;

    LL1TABLE[FieldDecMore - Program][END] = 24;

    LL1TABLE[FieldDecMore - Program][INTEGER] = 25;
    LL1TABLE[FieldDecMore - Program][CHAR] = 25;
    LL1TABLE[FieldDecMore - Program][ARRAY] = 25;

    LL1TABLE[IdList - Program][ID] = 26;

    LL1TABLE[IdMore - Program][SEMI] = 27;

    LL1TABLE[IdMore - Program][COMMA] = 28;

    LL1TABLE[VarDecpart - Program][PROCEDURE] = 29;
    LL1TABLE[VarDecpart - Program][BEGIN] = 29;

    LL1TABLE[VarDecpart - Program][VAR] = 30;

    LL1TABLE[VarDec - Program][VAR] = 31;

    LL1TABLE[VarDecList - Program][INTEGER] = 32;
    LL1TABLE[VarDecList - Program][CHAR] = 32;
    LL1TABLE[VarDecList - Program][ARRAY] = 32;
    LL1TABLE[VarDecList - Program][RECORD] = 32;
    LL1TABLE[VarDecList - Program][ID] = 32;

    LL1TABLE[VarDecMore - Program][PROCEDURE] = 33;
    LL1TABLE[VarDecMore - Program][BEGIN] = 33;

    LL1TABLE[VarDecMore - Program][INTEGER] = 34;
    LL1TABLE[VarDecMore - Program][CHAR] = 34;
    LL1TABLE[VarDecMore - Program][ARRAY] = 34;
    LL1TABLE[VarDecMore - Program][RECORD] = 34;
    LL1TABLE[VarDecMore - Program][ID] = 34;

    LL1TABLE[VarIdList - Program][ID] = 35;

    LL1TABLE[VarIdMore - Program][SEMI] = 36;

    LL1TABLE[VarIdMore - Program][COMMA] = 37;

    LL1TABLE[ProcDecpart - Program][BEGIN] = 38;

    LL1TABLE[ProcDecpart - Program][PROCEDURE] = 39;

    LL1TABLE[ProcDec - Program][PROCEDURE] = 40;

    LL1TABLE[ProcDecMore - Program][BEGIN] = 41;

    LL1TABLE[ProcDecMore - Program][PROCEDURE] = 42;

    LL1TABLE[ProcName - Program][ID] = 43;

    LL1TABLE[ParamList - Program][RPAREN] = 44;

    LL1TABLE[ParamList - Program][INTEGER] = 45;
    LL1TABLE[ParamList - Program][CHAR] = 45;
    LL1TABLE[ParamList - Program][ARRAY] = 45;
    LL1TABLE[ParamList - Program][RECORD] = 45;
    LL1TABLE[ParamList - Program][ID] = 45;
    LL1TABLE[ParamList - Program][VAR] = 45;

    LL1TABLE[ParamDecList - Program][INTEGER] = 46;
    LL1TABLE[ParamDecList - Program][CHAR] = 46;
    LL1TABLE[ParamDecList - Program][ARRAY] = 46;
    LL1TABLE[ParamDecList - Program][RECORD] = 46;
    LL1TABLE[ParamDecList - Program][ID] = 46;
    LL1TABLE[ParamDecList - Program][VAR] = 46;

    //LL1TABLE[ParamMore - Program][LPAREN] = 47;
    LL1TABLE[ParamMore - Program][RPAREN] = 47;

    LL1TABLE[ParamMore - Program][SEMI] = 48;

    LL1TABLE[Param - Program][INTEGER] = 49;
    LL1TABLE[Param - Program][CHAR] = 49;
    LL1TABLE[Param - Program][ARRAY] = 49;
    LL1TABLE[Param - Program][RECORD] = 49;
    LL1TABLE[Param - Program][ID] = 49;

    LL1TABLE[Param - Program][VAR] = 50;

    LL1TABLE[FormList - Program][ID] = 51;

    LL1TABLE[FidMore - Program][SEMI] = 52;
    LL1TABLE[FidMore - Program][RPAREN] = 52;

    LL1TABLE[FidMore - Program][COMMA] = 53;

    LL1TABLE[ProcDecPart - Program][TYPE] = 54;
    LL1TABLE[ProcDecPart - Program][VAR] = 54;
    LL1TABLE[ProcDecPart - Program][PROCEDURE] = 54;
    LL1TABLE[ProcDecPart - Program][BEGIN] = 54;

    LL1TABLE[ProcBody - Program][BEGIN] = 55;

    LL1TABLE[ProgramBody - Program][BEGIN] = 56;

    LL1TABLE[StmList - Program][ID] = 57;
    LL1TABLE[StmList - Program][IF] = 57;
    LL1TABLE[StmList - Program][WHILE] = 57;
    LL1TABLE[StmList - Program][RETURN] = 57;
    LL1TABLE[StmList - Program][READ] = 57;
    LL1TABLE[StmList - Program][WRITE] = 57;

    LL1TABLE[StmMore - Program][ELSE] = 58;
    LL1TABLE[StmMore - Program][FI] = 58;
    LL1TABLE[StmMore - Program][END] = 58;
    LL1TABLE[StmMore - Program][ENDWH] = 58;

    LL1TABLE[StmMore - Program][SEMI] = 59;

    LL1TABLE[Stm - Program][IF] = 60;

    LL1TABLE[Stm - Program][WHILE] = 61;

    LL1TABLE[Stm - Program][READ] = 62;

    LL1TABLE[Stm - Program][WRITE] = 63;

    LL1TABLE[Stm - Program][RETURN] = 64;

    LL1TABLE[Stm - Program][ID] = 65;

    LL1TABLE[AssCall - Program][ASSIGN] = 66;
    LL1TABLE[AssCall - Program][LMIDPAREN] = 66;


    LL1TABLE[AssCall - Program][LPAREN] = 67;

    LL1TABLE[AssignmentRest - Program][LMIDPAREN] = 68;
    LL1TABLE[AssignmentRest - Program][DOT] = 68;
    LL1TABLE[AssignmentRest - Program][ASSIGN] = 68;

    LL1TABLE[ConditionalStm - Program][IF] = 69;

    LL1TABLE[LoopStm - Program][WHILE] = 70;

    LL1TABLE[InputStm - Program][READ] = 71;

    LL1TABLE[Invar - Program][ID] = 72;

    LL1TABLE[OutputStm - Program][WRITE] = 73;

    LL1TABLE[ReturnStm - Program][RETURN] = 74;

    LL1TABLE[CallStmRest - Program][LPAREN] = 75;

    LL1TABLE[ActParamList - Program][RPAREN] = 76;

    LL1TABLE[ActParamList - Program][ID] = 77;
    LL1TABLE[ActParamList - Program][INTC] = 77;
    LL1TABLE[ActParamList - Program][LPAREN] = 77;

    LL1TABLE[ActParamMore - Program][RPAREN] = 78;

    LL1TABLE[ActParamMore - Program][COMMA] = 79;


    LL1TABLE[RelExp - Program][ID] = 80;
    LL1TABLE[RelExp - Program][INTC] = 80;
    LL1TABLE[RelExp - Program][LPAREN] = 80;

    LL1TABLE[OtherRelE - Program][EQ] = 81;
    LL1TABLE[OtherRelE - Program][LT] = 81;

    LL1TABLE[Exp - Program][ID] = 82;
    LL1TABLE[Exp - Program][INTC] = 82;
    LL1TABLE[Exp - Program][LPAREN] = 82;

    LL1TABLE[OtherTerm - Program][LT] = 83;
    LL1TABLE[OtherTerm - Program][EQ] = 83;
    LL1TABLE[OtherTerm - Program][RMIDPAREN] = 83;
    LL1TABLE[OtherTerm - Program][THEN] = 83;
    LL1TABLE[OtherTerm - Program][ELSE] = 83;
    LL1TABLE[OtherTerm - Program][FI] = 83;
    LL1TABLE[OtherTerm - Program][DO] = 83;
    LL1TABLE[OtherTerm - Program][ENDWH] = 83;
    LL1TABLE[OtherTerm - Program][RPAREN] = 83;
    LL1TABLE[OtherTerm - Program][END] = 83;
    LL1TABLE[OtherTerm - Program][SEMI] = 83;
    LL1TABLE[OtherTerm - Program][COMMA] = 83;

    LL1TABLE[OtherTerm - Program][MINUS] = 84;
    LL1TABLE[OtherTerm - Program][PLUS] = 84;

    LL1TABLE[Term - Program][ID] = 85;
    LL1TABLE[Term - Program][INTC] = 85;
    LL1TABLE[Term - Program][LPAREN] = 85;

    LL1TABLE[OtherFactor - Program][PLUS] = 86;
    LL1TABLE[OtherFactor - Program][MINUS] = 86;
    LL1TABLE[OtherFactor - Program][LT] = 86;
    LL1TABLE[OtherFactor - Program][EQ] = 86;
    LL1TABLE[OtherFactor - Program][RMIDPAREN] = 86;
    LL1TABLE[OtherFactor - Program][THEN] = 86;
    LL1TABLE[OtherFactor - Program][ELSE] = 86;
    LL1TABLE[OtherFactor - Program][FI] = 86;
    LL1TABLE[OtherFactor - Program][DO] = 86;
    LL1TABLE[OtherFactor - Program][ENDWH] = 86;
    LL1TABLE[OtherFactor - Program][RPAREN] = 86;
    LL1TABLE[OtherFactor - Program][END] = 86;
    LL1TABLE[OtherFactor - Program][SEMI] = 86;
    LL1TABLE[OtherFactor - Program][COMMA] = 86;

    LL1TABLE[OtherFactor - Program][OVER] = 87;
    LL1TABLE[OtherFactor - Program][TIMES] = 87;

    LL1TABLE[Factor - Program][LPAREN] = 88;

    LL1TABLE[Factor - Program][INTC] = 89;

    LL1TABLE[Factor - Program][ID] = 90;

    LL1TABLE[Variable - Program][ID] = 91;

    LL1TABLE[VariMore - Program][ASSIGN] = 92;
    LL1TABLE[VariMore - Program][TIMES] = 92;
    LL1TABLE[VariMore - Program][OVER] = 92;
    LL1TABLE[VariMore - Program][PLUS] = 92;
    LL1TABLE[VariMore - Program][MINUS] = 92;
    LL1TABLE[VariMore - Program][LT] = 92;
    LL1TABLE[VariMore - Program][EQ] = 92;
    LL1TABLE[VariMore - Program][THEN] = 92;
    LL1TABLE[VariMore - Program][ELSE] = 92;
    LL1TABLE[VariMore - Program][FI] = 92;
    LL1TABLE[VariMore - Program][DO] = 92;
    LL1TABLE[VariMore - Program][ENDWH] = 92;
    LL1TABLE[VariMore - Program][RPAREN] = 92;
    LL1TABLE[VariMore - Program][END] = 92;
    LL1TABLE[VariMore - Program][SEMI] = 92;
    LL1TABLE[VariMore - Program][COMMA] = 92;
    LL1TABLE[VariMore - Program][RMIDPAREN] = 92;


    LL1TABLE[VariMore - Program][LMIDPAREN] = 93;


    LL1TABLE[VariMore - Program][DOT] = 94;

    LL1TABLE[FieldVar - Program][ID] = 95;

    LL1TABLE[FieldVarMore - Program][ASSIGN] = 96;
    LL1TABLE[FieldVarMore - Program][TIMES] = 96;
    LL1TABLE[FieldVarMore - Program][OVER] = 96;
    LL1TABLE[FieldVarMore - Program][PLUS] = 96;
    LL1TABLE[FieldVarMore - Program][MINUS] = 96;
    LL1TABLE[FieldVarMore - Program][LT] = 96;
    LL1TABLE[FieldVarMore - Program][EQ] = 96;
    LL1TABLE[FieldVarMore - Program][THEN] = 96;
    LL1TABLE[FieldVarMore - Program][ELSE] = 96;
    LL1TABLE[FieldVarMore - Program][FI] = 96;
    LL1TABLE[FieldVarMore - Program][DO] = 96;
    LL1TABLE[FieldVarMore - Program][ENDWH] = 96;
    LL1TABLE[FieldVarMore - Program][RPAREN] = 96;
    LL1TABLE[FieldVarMore - Program][END] = 96;
    LL1TABLE[FieldVarMore - Program][SEMI] = 96;
    LL1TABLE[FieldVarMore - Program][COMMA] = 96;

    LL1TABLE[FieldVarMore - Program][LMIDPAREN] = 97;

    LL1TABLE[CmpOp - Program][LT] = 98;

    LL1TABLE[CmpOp - Program][EQ] = 99;

    LL1TABLE[AddOp - Program][PLUS] = 100;

    LL1TABLE[AddOp - Program][MINUS] = 101;

    LL1TABLE[MultOp - Program][TIMES] = 102;


    LL1TABLE[MultOp - Program][OVER] = 103;
}

void SynAnalyzer::InitLL1Table()
{
    synRules[0].push_back(LexType::ProgramBody);
    synRules[0].push_back(LexType::DeclarePart);
    synRules[0].push_back(LexType::ProgramHead);

    synRules[1].push_back(LexType::ProgramName);
    synRules[1].push_back(LexType::PROGRAM);

    synRules[2].push_back(LexType::ID);

    synRules[3].push_back(LexType::ProcDecpart);
    synRules[3].push_back(LexType::VarDecpart);
    synRules[3].push_back(LexType::TypeDecpart);

    //第5条规则右部为空

    synRules[5].push_back(LexType::TypeDec);

    synRules[6].push_back(LexType::TypeDecList);
    synRules[6].push_back(LexType::TYPE);

    synRules[7].push_back(LexType::TypeDecMore);
    synRules[7].push_back(LexType::SEMI);
    synRules[7].push_back(LexType::TypeDef);
    synRules[7].push_back(LexType::EQ);
    synRules[7].push_back(LexType::TypeId);

    //第9条规则为空

    synRules[9].push_back(LexType::TypeDecList);

    synRules[10].push_back(LexType::ID);

    synRules[11].push_back(LexType::BaseType);

    synRules[12].push_back(LexType::StructureType);

    synRules[13].push_back(LexType::ID);

    synRules[14].push_back(LexType::INTEGER);

    synRules[15].push_back(LexType::CHAR);

    synRules[16].push_back(LexType::ArrayType);

    synRules[17].push_back(LexType::RecType);

    synRules[18].push_back(LexType::BaseType);
    synRules[18].push_back(LexType::OF);
    synRules[18].push_back(LexType::RMIDPAREN);
    synRules[18].push_back(LexType::Top);
    synRules[18].push_back(LexType::UNDERANGE);
    synRules[18].push_back(LexType::Low);
    synRules[18].push_back(LexType::LMIDPAREN);
    synRules[18].push_back(LexType::ARRAY);

    synRules[19].push_back(LexType::INTC);

    synRules[20].push_back(LexType::INTC);

    synRules[21].push_back(LexType::END);
    synRules[21].push_back(LexType::FieldDecList);
    synRules[21].push_back(LexType::RECORD);

    synRules[22].push_back(LexType::FieldDecMore);
    synRules[22].push_back(LexType::SEMI);
    synRules[22].push_back(LexType::IdList);
    synRules[22].push_back(LexType::BaseType);

    synRules[23].push_back(LexType::FieldDecMore);
    synRules[23].push_back(LexType::SEMI);
    synRules[23].push_back(LexType::IdList);
    synRules[23].push_back(LexType::ArrayType);

    //第25条右部为空

    synRules[25].push_back(LexType::FieldDecList);

    synRules[26].push_back(LexType::IdMore);
    synRules[26].push_back(LexType::ID);

    //第28条右部为空

    synRules[28].push_back(LexType::IdList);
    synRules[28].push_back(LexType::COMMA);

    //第30条右部为空

    synRules[30].push_back(LexType::VarDec);

    synRules[31].push_back(LexType::VarDecList);
    synRules[31].push_back(LexType::VAR);

    synRules[32].push_back(LexType::VarDecMore);
    synRules[32].push_back(LexType::SEMI);
    synRules[32].push_back(LexType::VarIdList);
    synRules[32].push_back(LexType::TypeDef);

    //第34条右部为空

    synRules[34].push_back(LexType::VarDecList);

    synRules[35].push_back(LexType::VarIdMore);
    synRules[35].push_back(LexType::ID);

    //第37条右部为空

    synRules[37].push_back(LexType::VarIdList);
    synRules[37].push_back(LexType::COMMA);

    //第39条右部为空

    synRules[39].push_back(LexType::ProcDec);


    synRules[40].push_back(LexType::ProcDecMore);
    synRules[40].push_back(LexType::ProcBody);
    synRules[40].push_back(LexType::ProcDecPart);
    synRules[40].push_back(LexType::SEMI);
    synRules[40].push_back(LexType::RPAREN);
    synRules[40].push_back(LexType::ParamList);
    synRules[40].push_back(LexType::LPAREN);
    synRules[40].push_back(LexType::ProcName);
    synRules[40].push_back(LexType::PROCEDURE);


    //第42条右部为空

    synRules[42].push_back(LexType::ProcDeclaration);

    synRules[43].push_back(LexType::ID);

    //第45条右部为空

    synRules[45].push_back(LexType::ParamDecList);

    synRules[46].push_back(LexType::ParamMore);
    synRules[46].push_back(LexType::Param);

    //第48条右部为空

    synRules[48].push_back(LexType::ParamDecList);
    synRules[48].push_back(LexType::SEMI);

    synRules[49].push_back(LexType::FormList);
    synRules[49].push_back(LexType::TypeDef);

    synRules[50].push_back(LexType::FormList);
    synRules[50].push_back(LexType::TypeDef);
    synRules[50].push_back(LexType::VAR);

    synRules[51].push_back(LexType::FidMore);
    synRules[51].push_back(LexType::ID);

    //第53条右部为空

    synRules[53].push_back(LexType::FormList);
    synRules[53].push_back(LexType::COMMA);

    synRules[54].push_back(LexType::DeclarePart);

    synRules[55].push_back(LexType::ProgramBody);

    //synRules[56].push_back(LexType::DOT);
    synRules[56].push_back(LexType::END);
    synRules[56].push_back(LexType::StmList);
    synRules[56].push_back(LexType::BEGIN);

    synRules[57].push_back(LexType::StmMore);
    synRules[57].push_back(LexType::Stm);

    //第59条右部为空

    synRules[59].push_back(LexType::StmList);
    synRules[59].push_back(LexType::SEMI);

    synRules[60].push_back(LexType::ConditionalStm);

    synRules[61].push_back(LexType::LoopStm);

    synRules[62].push_back(LexType::InputStm);

    synRules[63].push_back(LexType::OutputStm);

    synRules[64].push_back(LexType::ReturnStm);

    synRules[65].push_back(LexType::AssCall);
    synRules[65].push_back(LexType::ID);

    synRules[66].push_back(LexType::AssignmentRest);

    synRules[67].push_back(LexType::CallStmRest);

    synRules[68].push_back(LexType::Exp);
    synRules[68].push_back(LexType::ASSIGN);
    synRules[68].push_back(LexType::VariMore);

    synRules[69].push_back(LexType::FI);
    synRules[69].push_back(LexType::StmList);
    synRules[69].push_back(LexType::ELSE);
    synRules[69].push_back(LexType::StmList);
    synRules[69].push_back(LexType::THEN);
    synRules[69].push_back(LexType::RelExp);
    synRules[69].push_back(LexType::IF);

    synRules[70].push_back(LexType::ENDWH);
    synRules[70].push_back(LexType::StmList);
    synRules[70].push_back(LexType::DO);
    synRules[70].push_back(LexType::RelExp);
    synRules[70].push_back(LexType::WHILE);

    synRules[71].push_back(LexType::RPAREN);
    synRules[71].push_back(LexType::Invar);
    synRules[71].push_back(LexType::LPAREN);
    synRules[71].push_back(LexType::READ);

    synRules[72].push_back(LexType::ID);

    synRules[73].push_back(LexType::RPAREN);
    synRules[73].push_back(LexType::Exp);
    synRules[73].push_back(LexType::LPAREN);
    synRules[73].push_back(LexType::WRITE);

    synRules[74].push_back(LexType::RETURN);

    synRules[75].push_back(LexType::RPAREN);
    synRules[75].push_back(LexType::ActParamList);
    synRules[75].push_back(LexType::LPAREN);

    //第七十七条规则右部为空

    synRules[77].push_back(LexType::ActParamMore);
    synRules[77].push_back(LexType::Exp);

    //第七十九条规则右部为空

    synRules[79].push_back(LexType::ActParamList);
    synRules[79].push_back(LexType::COMMA);

    synRules[80].push_back(LexType::OtherRelE);
    synRules[80].push_back(LexType::Exp);

    synRules[81].push_back(LexType::Exp);
    synRules[81].push_back(LexType::CmpOp);

    synRules[82].push_back(LexType::OtherTerm);
    synRules[82].push_back(LexType::Term);

    //第八十四条规则右部为空

    synRules[84].push_back(LexType::Exp);
    synRules[84].push_back(LexType::AddOp);

    synRules[85].push_back(LexType::OtherFactor);
    synRules[85].push_back(LexType::Factor);

    //第八十七条规则右部为空

    synRules[87].push_back(LexType::Term);
    synRules[87].push_back(LexType::MultOp);

    synRules[88].push_back(LexType::RPAREN);
    synRules[88].push_back(LexType::Exp);
    synRules[88].push_back(LexType::LPAREN);

    synRules[89].push_back(LexType::INTC);

    synRules[90].push_back(LexType::Variable);

    synRules[91].push_back(LexType::VariMore);
    synRules[91].push_back(LexType::ID);

    //第九十三条规则右部为空

    synRules[93].push_back(LexType::RMIDPAREN);
    synRules[93].push_back(LexType::Exp);
    synRules[93].push_back(LexType::LMIDPAREN);

    synRules[94].push_back(LexType::FieldVar);
    synRules[94].push_back(LexType::DOT);

    synRules[95].push_back(LexType::FieldVarMore);
    synRules[95].push_back(LexType::ID);

    //第九十七条规则右部为空

    synRules[97].push_back(LexType::RMIDPAREN);
    synRules[97].push_back(LexType::Exp);
    synRules[97].push_back(LexType::LMIDPAREN);

    synRules[98].push_back(LexType::LT);

    synRules[99].push_back(LexType::EQ);

    synRules[100].push_back(LexType::PLUS);

    synRules[101].push_back(LexType::MINUS);

    synRules[102].push_back(LexType::TIMES);

    synRules[103].push_back(LexType::OVER);
}